﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace NewFormatProject.Infrastructure.EFCore
{
    public partial class Core2Context : DbContext
    {
        public Core2Context()
        {
        }

        public Core2Context(DbContextOptions<Core2Context> options)
            : base(options)
        {
        }

        public virtual DbSet<ActionLogs> ActionLogs { get; set; }
        public virtual DbSet<Jobs> Jobs { get; set; }
        public virtual DbSet<LoginLogs> LoginLogs { get; set; }
        public virtual DbSet<RightConfigDetails> RightConfigDetails { get; set; }
        public virtual DbSet<SysDepartments> SysDepartments { get; set; }
        public virtual DbSet<SysErrorLogs> SysErrorLogs { get; set; }
        public virtual DbSet<SysRightConfigs> SysRightConfigs { get; set; }
        public virtual DbSet<SysRights> SysRights { get; set; }
        public virtual DbSet<SysUsers> SysUsers { get; set; }
        public virtual DbSet<UserRights> UserRights { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseMySql("server=localhost;database=Core2;user=root;password=Window123456", x => x.ServerVersion("8.0.41-mysql"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<ActionLogs>(entity =>
            {
                entity.HasKey(e => e.AlId)
                    .HasName("PRIMARY");

                entity.ToTable("action_logs");

                entity.HasComment("行为日志表");

                entity.HasIndex(e => e.AlUserId)
                    .HasName("al_user_id");

                entity.Property(e => e.AlId)
                    .HasColumnName("al_id")
                    .HasComment("编号");

                entity.Property(e => e.AlAffectedRows)
                    .HasColumnName("al_affected_rows")
                    .HasComment("受影响行数");

                entity.Property(e => e.AlCreateTime)
                    .HasColumnName("al_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.AlIp)
                    .IsRequired()
                    .HasColumnName("al_ip")
                    .HasColumnType("varchar(20)")
                    .HasComment("ip地址")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.AlMessage)
                    .IsRequired()
                    .HasColumnName("al_message")
                    .HasColumnType("varchar(200)")
                    .HasComment("消息")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.AlRequestMethod)
                    .IsRequired()
                    .HasColumnName("al_request_method")
                    .HasColumnType("varchar(10)")
                    .HasComment("请求方法")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.AlRequestParams)
                    .IsRequired()
                    .HasColumnName("al_request_params")
                    .HasColumnType("text")
                    .HasComment("请求参数")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.AlRequestUrl)
                    .IsRequired()
                    .HasColumnName("al_request_url")
                    .HasColumnType("varchar(200)")
                    .HasComment("请求地址")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.AlUserId)
                    .HasColumnName("al_user_id")
                    .HasComment("请求人");

                entity.HasOne(d => d.AlUser)
                    .WithMany(p => p.ActionLogs)
                    .HasForeignKey(d => d.AlUserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("action_logs_ibfk_1");
            });

            modelBuilder.Entity<Jobs>(entity =>
            {
                entity.HasKey(e => e.JId)
                    .HasName("PRIMARY");

                entity.ToTable("jobs");

                entity.HasComment("职位表");

                entity.HasIndex(e => e.JDepartmentId)
                    .HasName("j_department_id");

                entity.Property(e => e.JId)
                    .HasColumnName("j_id")
                    .HasComment("编号");

                entity.Property(e => e.JCreateTime)
                    .HasColumnName("j_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.JDepartmentId)
                    .HasColumnName("j_department_id")
                    .HasComment("所属部门");

                entity.Property(e => e.JDescription)
                    .HasColumnName("j_description")
                    .HasColumnType("varchar(1000)")
                    .HasComment("描述")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.JName)
                    .IsRequired()
                    .HasColumnName("j_name")
                    .HasColumnType("varchar(200)")
                    .HasComment("名称")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.HasOne(d => d.JDepartment)
                    .WithMany(p => p.Jobs)
                    .HasForeignKey(d => d.JDepartmentId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("jobs_ibfk_1");
            });

            modelBuilder.Entity<LoginLogs>(entity =>
            {
                entity.HasKey(e => e.LlId)
                    .HasName("PRIMARY");

                entity.ToTable("login_logs");

                entity.HasComment("登录日志表");

                entity.HasIndex(e => e.LlUserId)
                    .HasName("ll_user_id");

                entity.Property(e => e.LlId)
                    .HasColumnName("ll_id")
                    .HasComment("编号");

                entity.Property(e => e.LlCode)
                    .IsRequired()
                    .HasColumnName("ll_code")
                    .HasColumnType("varchar(32)")
                    .HasComment("登录码")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.LlCreateTime)
                    .HasColumnName("ll_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.LlMessage)
                    .HasColumnName("ll_message")
                    .HasColumnType("varchar(200)")
                    .HasComment("登录消息")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.LlUserId)
                    .HasColumnName("ll_user_id")
                    .HasComment("登录人");

                entity.HasOne(d => d.LlUser)
                    .WithMany(p => p.LoginLogs)
                    .HasForeignKey(d => d.LlUserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("login_logs_ibfk_1");
            });

            modelBuilder.Entity<RightConfigDetails>(entity =>
            {
                entity.HasKey(e => e.RcdId)
                    .HasName("PRIMARY");

                entity.ToTable("right_config_details");

                entity.HasComment("权限配置详情表");

                entity.HasIndex(e => e.RcdJobId)
                    .HasName("rcd_job_id");

                entity.HasIndex(e => e.RcdRightConfigId)
                    .HasName("rcd_right_config_id");

                entity.HasIndex(e => e.RcdRightId)
                    .HasName("right_config_details_ibfk_1");

                entity.Property(e => e.RcdId)
                    .HasColumnName("rcd_id")
                    .HasComment("编号");

                entity.Property(e => e.RcdJobId)
                    .HasColumnName("rcd_job_id")
                    .HasComment("职位");

                entity.Property(e => e.RcdRightConfigId)
                    .HasColumnName("rcd_right_config_id")
                    .HasComment("权限配置");

                entity.Property(e => e.RcdRightId)
                    .HasColumnName("rcd_right_id")
                    .HasComment("权限");

                entity.HasOne(d => d.RcdJob)
                    .WithMany(p => p.RightConfigDetails)
                    .HasForeignKey(d => d.RcdJobId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("right_config_details_ibfk_2");

                entity.HasOne(d => d.RcdRightConfig)
                    .WithMany(p => p.RightConfigDetails)
                    .HasForeignKey(d => d.RcdRightConfigId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("right_config_details_ibfk_3");

                entity.HasOne(d => d.RcdRight)
                    .WithMany(p => p.RightConfigDetails)
                    .HasForeignKey(d => d.RcdRightId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("right_config_details_ibfk_1");
            });

            modelBuilder.Entity<SysDepartments>(entity =>
            {
                entity.HasKey(e => e.DId)
                    .HasName("PRIMARY");

                entity.ToTable("sys_departments");

                entity.HasComment("部门主表");

                entity.HasIndex(e => e.DParentId)
                    .HasName("d_parent_id");

                entity.Property(e => e.DId)
                    .HasColumnName("d_id")
                    .HasComment("编号");

                entity.Property(e => e.DCreateTime)
                    .HasColumnName("d_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.DDescription)
                    .HasColumnName("d_description")
                    .HasColumnType("varchar(1000)")
                    .HasComment("描述")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.DName)
                    .IsRequired()
                    .HasColumnName("d_name")
                    .HasColumnType("varchar(200)")
                    .HasComment("名称")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.DParentId)
                    .HasColumnName("d_parent_id")
                    .HasComment("上级部门");

                entity.HasOne(d => d.DParent)
                    .WithMany(p => p.InverseDParent)
                    .HasForeignKey(d => d.DParentId)
                    .HasConstraintName("sys_departments_ibfk_1");
            });

            modelBuilder.Entity<SysErrorLogs>(entity =>
            {
                entity.HasKey(e => e.ElId)
                    .HasName("PRIMARY");

                entity.ToTable("sys_error_logs");

                entity.HasComment("错误日志主表");

                entity.Property(e => e.ElId)
                    .HasColumnName("el_id")
                    .HasComment("编号");

                entity.Property(e => e.ElCreateTime)
                    .HasColumnName("el_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.ElErrorTime)
                    .HasColumnName("el_error_time")
                    .HasColumnType("datetime")
                    .HasComment("报错时间");

                entity.Property(e => e.ElMessage)
                    .IsRequired()
                    .HasColumnName("el_message")
                    .HasColumnType("varchar(200)")
                    .HasComment("错误消息")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.ElParams)
                    .HasColumnName("el_params")
                    .HasColumnType("text")
                    .HasComment("参数")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.ElStackTrack)
                    .IsRequired()
                    .HasColumnName("el_stack_track")
                    .HasColumnType("text")
                    .HasComment("堆栈跟踪")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.ElUrl)
                    .IsRequired()
                    .HasColumnName("el_url")
                    .HasColumnType("varchar(200)")
                    .HasComment("请求地址")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");
            });

            modelBuilder.Entity<SysRightConfigs>(entity =>
            {
                entity.HasKey(e => e.RcId)
                    .HasName("PRIMARY");

                entity.ToTable("sys_right_configs");

                entity.HasComment("权限配置主表");

                entity.Property(e => e.RcId)
                    .HasColumnName("rc_id")
                    .HasComment("编号");

                entity.Property(e => e.RcCreateTime)
                    .HasColumnName("rc_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.RcDescription)
                    .IsRequired()
                    .HasColumnName("rc_description")
                    .HasColumnType("varchar(500)")
                    .HasComment("描述")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.RcIsBan)
                    .HasColumnName("rc_is_ban")
                    .HasComment("是否禁用");

                entity.Property(e => e.RcIsPublish)
                    .HasColumnName("rc_is_publish")
                    .HasComment("是否发布");

                entity.Property(e => e.RcName)
                    .IsRequired()
                    .HasColumnName("rc_name")
                    .HasColumnType("varchar(50)")
                    .HasComment("名称")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");
            });

            modelBuilder.Entity<SysRights>(entity =>
            {
                entity.HasKey(e => e.RId)
                    .HasName("PRIMARY");

                entity.ToTable("sys_rights");

                entity.HasComment("权限主表");

                entity.HasIndex(e => e.RParentId)
                    .HasName("r_parent_id");

                entity.Property(e => e.RId)
                    .HasColumnName("r_id")
                    .HasComment("编号");

                entity.Property(e => e.RCreateTime)
                    .HasColumnName("r_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.RHasMenu)
                    .HasColumnName("r_has_menu")
                    .HasComment("是否显示在菜单中");

                entity.Property(e => e.RIsBan)
                    .HasColumnName("r_is_ban")
                    .HasComment("是否禁用");

                entity.Property(e => e.RName)
                    .IsRequired()
                    .HasColumnName("r_name")
                    .HasColumnType("varchar(50)")
                    .HasComment("名称")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.RParentId)
                    .HasColumnName("r_parent_id")
                    .HasComment("父级权限");

                entity.Property(e => e.RUrl)
                    .IsRequired()
                    .HasColumnName("r_url")
                    .HasColumnType("varchar(500)")
                    .HasComment("所管控的地址")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.HasOne(d => d.RParent)
                    .WithMany(p => p.InverseRParent)
                    .HasForeignKey(d => d.RParentId)
                    .HasConstraintName("sys_rights_ibfk_1");
            });

            modelBuilder.Entity<SysUsers>(entity =>
            {
                entity.HasKey(e => e.UId)
                    .HasName("PRIMARY");

                entity.ToTable("sys_users");

                entity.HasComment("用户主表");

                entity.HasIndex(e => e.UAccount)
                    .HasName("u_account")
                    .IsUnique();

                entity.HasIndex(e => e.UJobId)
                    .HasName("u_job_id");

                entity.Property(e => e.UId)
                    .HasColumnName("u_id")
                    .HasComment("编号");

                entity.Property(e => e.UAccount)
                    .IsRequired()
                    .HasColumnName("u_account")
                    .HasColumnType("varchar(16)")
                    .HasComment("账号")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.UAvatar)
                    .HasColumnName("u_avatar")
                    .HasColumnType("varchar(200)")
                    .HasComment("用户头像")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.UCreateTime)
                    .HasColumnName("u_create_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("'now()'")
                    .HasComment("创建时间");

                entity.Property(e => e.UIsActive)
                    .HasColumnName("u_is_active")
                    .HasComment("是否激活");

                entity.Property(e => e.UIsBan)
                    .HasColumnName("u_is_ban")
                    .HasComment("是否禁用");

                entity.Property(e => e.UJobId)
                    .HasColumnName("u_job_id")
                    .HasComment("职位");

                entity.Property(e => e.UName)
                    .IsRequired()
                    .HasColumnName("u_name")
                    .HasColumnType("varchar(16)")
                    .HasComment("姓名")
                    .HasCharSet("utf8mb3")
                    .HasCollation("utf8mb3_general_ci");

                entity.Property(e => e.UPassword)
                    .IsRequired()
                    .HasColumnName("u_password")
                    .HasColumnType("varchar(50)")
                    .HasComment("密码")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.UPhone)
                    .IsRequired()
                    .HasColumnName("u_phone")
                    .HasColumnType("char(11)")
                    .HasComment("电话")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.URole)
                    .IsRequired()
                    .HasColumnName("u_role")
                    .HasColumnType("varchar(32)")
                    .HasDefaultValueSql("'_utf8mb4\\\\''æ®éç¨æ·\\\\'''")
                    .HasComment("角色")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.Property(e => e.USalt)
                    .IsRequired()
                    .HasColumnName("u_salt")
                    .HasColumnType("varchar(32)")
                    .HasDefaultValueSql("'replace(uuid(),_utf8mb3\\\\''-\\\\'',_utf8mb4\\\\''\\\\'')'")
                    .HasComment("用户盐值")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_unicode_ci");

                entity.HasOne(d => d.UJob)
                    .WithMany(p => p.SysUsers)
                    .HasForeignKey(d => d.UJobId)
                    .HasConstraintName("sys_users_ibfk_1");
            });

            modelBuilder.Entity<UserRights>(entity =>
            {
                entity.HasKey(e => e.UrId)
                    .HasName("PRIMARY");

                entity.ToTable("user_rights");

                entity.HasComment("用户权限表");

                entity.HasIndex(e => e.UrRightId)
                    .HasName("ur_right_id");

                entity.HasIndex(e => e.UrUserId)
                    .HasName("ur_user_id");

                entity.Property(e => e.UrId)
                    .HasColumnName("ur_id")
                    .HasComment("编号");

                entity.Property(e => e.UrRightId)
                    .HasColumnName("ur_right_id")
                    .HasComment("权限");

                entity.Property(e => e.UrUserId)
                    .HasColumnName("ur_user_id")
                    .HasComment("用户");

                entity.HasOne(d => d.UrRight)
                    .WithMany(p => p.UserRights)
                    .HasForeignKey(d => d.UrRightId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("user_rights_ibfk_1");

                entity.HasOne(d => d.UrUser)
                    .WithMany(p => p.UserRights)
                    .HasForeignKey(d => d.UrUserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("user_rights_ibfk_2");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
